import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
from sklearn import svm
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import accuracy_score, recall_score, precision_score
from sklearn.datasets import load_breast_cancer
from time import time

if __name__ == '__main__':
    data = load_breast_cancer()
    x = data.data
    y = data.target

    plt.scatter(x[:, 0], x[:, 1], c=y)
    plt.show()

    x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=0)
    kernels = ['linear', 'poly', 'rbf', 'sigmoid']

    for kernel in kernels:
        start_time = time()
        # gamma:核函数的系数，仅当核函数为'rbf'、'poly'或'sigmoid'时有效
        # cache_size:内核缓存的大小，用于限制计算量
        clf = svm.SVC(kernel=kernel, gamma='auto', degree=2, cache_size=200, random_state=0).fit(x_train, y_train)
        end_time = time()
        elapsed_time_milliseconds = (end_time - start_time) * 1000
        print("kernel = {}, acc = {},elapsed_time_milliseconds ={}ms".format(kernel, clf.score(x_test, y_test),
                                                                             elapsed_time_milliseconds))
